package com.ricchieri.service;

import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.ricchieri.dao.interf.IPassengerTypeDao;
import com.ricchieri.filter.BasicFilter;
import com.ricchieri.model.PassengerType;
import com.ricchieri.service.interf.IPassengerTypeService;
import com.ricchieri.util.FacesUtil;

@Transactional(readOnly = true)
public class PassengerTypeService implements IPassengerTypeService, Serializable {
	private static final long serialVersionUID = -1633622792643498186L;
	IPassengerTypeDao passengerTypeDao;
	
	@Override
	@Transactional(readOnly = true)
	public List<PassengerType> getAllPassengerTypes() {
		BasicFilter filter = new BasicFilter();
		return passengerTypeDao.getAllPassengerTypes(filter);
	}

	public IPassengerTypeDao getPassengerTypeDao() {
		return passengerTypeDao;
	}

	public void setPassengerTypeDao(IPassengerTypeDao passengerTypeDao) {
		this.passengerTypeDao = passengerTypeDao;
	}
	
	@Override
	public PassengerType getPassengerTypeById(BasicFilter passengerTypeFilter) {
		return getPassengerTypeDao().getPassengerTypeById(passengerTypeFilter);
	}		
	
	@Override
	public Map<String, String> getComboPassengerType() {
		List<PassengerType> passengerTypeValues = this.getAllPassengerTypes();

		HashMap<String, String> passengerTypeCombo = new LinkedHashMap<String, String>();

		for (PassengerType passengerType : passengerTypeValues) {
			passengerTypeCombo.put(FacesUtil.getMessage(passengerType.getDescription()), String.valueOf(passengerType.getId()));
		}

		return passengerTypeCombo;
	}
}
